<template>
  <div class="product-manage" >
    <!--    <el-button type="primary" @click="showAddDialog">添加商品</el-button>-->
    <el-table  highlight-current-row :data="commodities"  style="width: 100%">
      <el-table-column prop="cid" label="编号" width="250" ></el-table-column>
      <el-table-column prop="cname" label="名称"></el-table-column>
      <el-table-column  label="商品图片">
        <template slot-scope="scope">
          <el-image
              style="width: 100px; height: 100px"
              :src="scope.row.image"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="typename" label="一级分类"></el-table-column>
      <el-table-column prop="type" label="二级分类"></el-table-column>
      <el-table-column prop="cnumber" label="数量"></el-table-column>
      <el-table-column prop="date" label="日期"></el-table-column>
      <el-table-column prop="username" label="上架者"></el-table-column>
      <el-table-column width="150" label="操作">

        <template slot-scope="scope">
          <el-button size="small"  type="primary" @click="deleteProduct(scope.row,scope.$index,commodities)">上架</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from 'axios'
import { Message, MessageBox } from 'element-ui'

export default {
  data() {
    return {
      commodities: [],
    }
  },
  mounted() {
    this.getOrders()
  },
  methods: {
    getOrders() {
      axios.get('http://localhost:8088/commodity_b/findAllCheckCommodityVO')
          .then(response => {
            console.log(response.data.data)
            this.commodities = response.data.data
            // this.categories=response.data.categories
          })
          .catch(error => {
            console.log(error)
          })
    },
    deleteProduct(product,index,rows) {
      MessageBox.confirm(' 是否上架此商品?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
          .then(() => {
            axios.delete('http://localhost:8088/commodity_b/upCommodityByCID',{params:{
                cid:product.cid
              }})
                .then(() => {
                  // this.getProducts()
                  rows.splice(index,1);
                  Message.success('上架成功')
                })
                .catch(error => {
                  console.log(error)
                })
          })
          .catch(() => {
            // do nothing
          })
    }
  }
}
</script>

<style scoped> .product-manage { padding: 20px; } </style>
